/**
 * @a https://leetcode.cn/problems/valid-sudoku/description/
 */

#include "common.h"

class Solution {
public:
    bool isValidSudoku(vector<vector<char>>& board) {
        vector<int> rows(9,0);
        vector<int> cols(9,0);
        vector<int> blocks(9,0);
        for(int i = 0; i < 9; ++i){
            for(int j = 0; j < 9; ++j){
                if(board[i][j] != '.'){
                    int val = board[i][j] - '0';
                    if((rows[i] >> val) & 1 || (cols[j] >> val) & 1 || (blocks[(i/3)*3 + j/3] >> val) & 1)
                        return false;
                    rows[i] |= 1 << val;
                    cols[j] |= 1 << val;
                    blocks[(i/3)*3+j/3] |= 1 << val;
                }
            }
        }
        return true;
    }
};